<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<title>BOM单新增</title>
		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath}/css/public.css">
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/js/sorttable.js"></script>
		<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/public.js"></script>
		<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/baseset.js"></script>
		<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/selectrow.js"></script>
		<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/validate.js"></script>
			<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/ajax.js"></script>
		<script type="text/javascript">						
		function editBomBill(){
			var materialCode = document.getElementById("materialCode");
			var unitName = document.getElementById("unitName");
			var materialName = document.getElementById("materialName");
			var memo = document.getElementById("memo");
			var materialAttribute = document.getElementById("materialAttribute");
			var number = document.getElementById("number");
			var fee = document.getElementById("fee");
			var spec = document.getElementById("spec");
			
			if(!isNotNull(number,'数量')||!f_check_float(number,'数量')||!f_check_stringLength(number,'数量',12))
				return false ;	
				
			if(!isNotNull(fee,'费用')||!f_check_float(fee,'费用')||!f_check_stringLength(fee,'费用',12))
				return false ;	
				
			if(!isNotNull(materialCode,'物料代码')||!f_check_ZhOrNumOrLett(materialCode,'物料代码'))
				return false ;	
			
			if(!(isNotNull(unitName,'单位')&&f_check_ZhOrNumOrLett(unitName,'单位')))
				return false ;	
			
			if(!f_check_stringLength(memo,'备注',12)) return false;	
			
			var t = document.getElementById("mbody");
			
			if(isNotZeroRow(t.rows.length)){
				var bomDetailRows = document.getElementsByName("bomDetailRow");
			
			for(var i=0;i<t.rows.length;i++){			
				var tempMaterialCode = document.getElementById("materialCode"+i);
				var tempMaterialName = document.getElementById("materialName"+i);				
				var tempMaterialId = document.getElementById("materialId"+i);
				//alert("物料ID："+tempMaterialId.value);				
				var tempStorageId = document.getElementById("storageId"+i);				
				var tempSpec = document.getElementById("spec"+i);
				var tempMaterialAttribute = document.getElementById("materialAttribute"+i);
				var tempAssistantAttribute = document.getElementById("assistantAttribute"+i);
				//alert("辅助属性ID："+tempAssistantAttribute.value);
				var tempMeasureUnitId = document.getElementById("measureUnitId"+i);
				//  alert("计量单位ID："+tempMeasureUnitId.value);
				var tempMeasureUnit = document.getElementById("measureUnitName"+i);
				var tempBasicMeasureUnitName = document.getElementById("basicMeasureUnitName"+i);
				var tempBasicCost = document.getElementById("basicCost"+i);
				var tempCost = document.getElementById("cost"+i);
				//alert("用量："+tempCost.value);
				var tempLossPercent = document.getElementById("lossPercent"+i);
				//alert("损耗率："+tempLossPercent.value);
				var tempUsedState = document.getElementById("usedState"+i);
				var tempStorageName = document.getElementById("storageName"+i);
			
				if(!isNotNullOfRow(tempMaterialCode,'物料代码',i)||!f_check_ZhOrNumOrLettOfRow(tempMaterialCode,'物料代码',i))
					return false ;	
			
				if(!(isNotNullOfRow(tempMeasureUnit,'单位',i)&&f_check_ZhOrNumOrLettOfRow(tempMeasureUnit,'单位',i)))
				return false ;	
				
				if(!(isNotNullOfRow(tempStorageName,'发料仓库',i)	&& f_check_stringLengthOfRow(tempStorageName,'发料仓库',12,i)	))
				return false ;	
				
				if(!isNotNullOfRow(tempCost,'用量',i)||!f_check_floatOfRow(tempCost,'用量',i)||!f_check_stringLengthOfRow(tempCost,'用量',12,i))
				return false ;	
			
				if(!f_check_floatOfRow(tempLossPercent,'损耗率',i)||!f_check_stringLengthOfRow(tempLossPercent,'损耗率',12,i))
				return false ;
				bomDetailRows[i].value = tempMaterialId.value+","+tempMaterialAttribute.value+","+tempStorageId.value+","+tempCost.value+","+tempLossPercent.value+","+tempMeasureUnitId.value;
				}		
					
				var formname = document.getElementById("BomBillForm");//form的ID
				formname.action = "editBOMBill.action";			
				formname.submit();	
			}else
				return false;
		}
		</script>
	</head>
	<body>
		<s:form theme="simple" id="BomBillForm" name="BomBillForm">
			<div align="center" id="info_all" style="width: 1105px; margin: 6px;">
				<div id="info_top" align="left">
					BOM单编辑
				</div>
				<div style="padding: 4px; width: 1000px; margin-top: 6px;">
					<table
						style="margin-top: 10px; background: #fbfbfb; color: #403040; text-align: left; width: 1000px"
						align="center">
						<tr>
							<td width="80px">
								BOM组别
							</td>
							<td width="140px">
								<input type="hidden" name="bomGroupID" id="bomGroupID"
									value="${editedBOMBill.bomGroupId}" />
								<input type="text" size="12" readonly="true"
									value="${editedBOMBill.bomGroupName}" name="bomGroupName" />
							</td>
							<td width="80px">
								BOM编号
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true"
									value="${editedBOMBill.bomBillCode}" name="bomBillCode" />
							</td>
							<td width="80px">
								状态
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true"
									value="${editedBOMBill.state}" name="state" />
							</td>
							<td width="80px">
								物料代码
							</td>
							<td width="140px">
								<s:hidden name="materialId" id="materialId" value="%{editedBOMBill.verifyProjectMaterialId}"></s:hidden>
								<input type="text" size="12" readonly="true" id="materialCode"
									name="materialCode"
									value="${editedBOMBill.verifyProjectMaterialCode}" />
								<img src="images/kookup.gif" style="cursor: pointer"
									onclick="openWin('selectMaterialAction.action','material',750,700,0)">
							</td>
							<td width="80px">
								物料名称
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true" id="materialName"
									name="materialName"
									value="${editedBOMBill.verifyProjectMaterialName}" />
							</td>
						</tr>
						<tr>
							<td width="80px">
								单位
							</td>
							<td width="140px">
								<s:hidden name="unitId" id="unitId"></s:hidden>
								<input type="text" size="12" readonly="true" id="unitName"
									name="unitName" value="${editedBOMBill.unit}" />
								<img src="images/kookup.gif" style="cursor: pointer"
									onclick="openWin('selectMeasure.action','measureUnit',750,700,0)">
							</td>
							<td width="80px">
								数量
							</td>
							<td width="140px">
								<input type="text" size="12" id="number" name="number"
									value="1.00" value="${editedBOMBill.number}" />
							<td width="80px">
								费用
							</td>
							<td width="140px">
								<input type="text" size="12" id="fee" name="fee" value="0.00"
									value="${editedBOMBill.fee}" />
							</td>

							<td width="80px">
								物料属性
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true"
									id="materialAttribute" name="materialAttribute"
									value="${editedBOMBill.verifyProjectMaterialMaterialAttribute}" />
							</td>
							<td width="80px">
								辅助属性
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true"
									id="assistantAttribute" name="assistantAttribute"
									value="${editedBOMBill.attributeBasicType}" />
							</td>
						</tr>
						<tr>
							<td width="80px">
								修改人
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true"
									value="${editedBOMBill.billEditerName}" id="billMakerName"
									name="billMakerName" />
							</td>
							<td width="80px">
								修改日期
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true"
									value="${editedBOMBill.billEditerDate}" id="billMakeDate"
									name="billMakeDate" />
							</td>
							<td width="80px">
								审核人
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true"
									value="${editedBOMBill.billAuditerName}" />
							<td width="80px">
								审核日期
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true"
									value="${editedBOMBill.billAuditDate}" />
							</td>
							<td width="80px">
								规格
							</td>
							<td width="140px">
								<input type="text" size="12" readonly="true" id="spec"
									name="spec" value="${editedBOMBill.verifyProjectMaterialSpec}" />
							</td>
						</tr>
						<tr>
							<td width="80px">
								备注
							</td>
							<td width="140px">
								<input type="text" size="12" id="memo" name="memo"
									value="${editedBOMBill.memo}" />
							</td>
							<td width="80px"></td>
							<td width="140px"></td>

							<td width="80px"></td>
							<td width="140px">
							<td width="80px"></td>
							<td width="140px"></td>
							<td width="80px"></td>
							<td width="140px"></td>
						</tr>
					</table>
				</div>
				<div id="info_top" align="left">
					物料明细
					<input type="button" value="新增" onclick="addMaterialOfRow()"
						onmouseover="this.className='btnover'"
						onmouseout="this.className='btnout'" id="btnsize" />
					<input type="button" value="删除" onclick="delrow()"
						onmouseover="this.className='btnover'"
						onmouseout="this.className='btnout'" id="btnsize" />
					<hr>
				</div>
				<div
					style="width: 1100px; margin-top: -12px; margn-left: -10px; overflow-X: scroll; overflow-Y: scroll; height: 460px;">
					<table align="left"
						style="margin-top: 10px; color: #403040; width: 1100px;"
						id="info_table" cellspacing="1px" cellpadding="1px">
						<thead id="head">
							<tr>
								<th width="10px">
									<input type="checkbox" name="checkbox" onClick="selectAll()" />
								</th>
								<th width="90px">
									物料代码
								</th>
								<th width="90px">
									物料名称
								</th>
								<th width="90px">
									规格型号
								</th>
								<th width="90px">
									物料属性
								</th>
								<th width="90px">
									辅助属性
								</th>
								<th width="90px">
									单位
								</th>
								<th width="90px">
									基本单位
								</th>
								<th width="90px">
									基本单位用量
								</th>
								<th width="90px">
									用量
								</th>
								<th width="90px">
									损耗率
								</th>
								<th width="90px">
									使用状态
								</th>
								<th width="90px">
									发料仓库
								</th>
							</tr>
						</thead>
						<tbody id="mbody">
							<s:if test="!editedBOMBillDetailList.isEmpty">
								<s:iterator value="editedBOMBillDetailList" status="status">
									<tr>
										<td>
											<input type='hidden' name='bomDetailRow' id='bomDetailRow' />
											<input type='checkbox' name='checkbox' />
										</td>
										<td>
											<input type='hidden' id='materialId${status.index}'
												value='${materialId}' />
											<input name='materialCode' id='materialCode${status.index}'
												value='${materialCode}' size='8'
												ondblclick='openWinMaterial(${status.index},750,700,0)' />
										</td>
										<td>
											<input name='materialName' id='materialName${status.index}'
												readonly='true' type='text' size='8' value='${materialName}' />
										</td>
										<td>
											<input name='spec' id='spec${status.index}' readonly='true'
												type='text' size='8' value='${spec}' />
										</td>
										<td>
											<input name='materialAttribute'
												id='materialAttribute${status.index}' readonly='true'
												type='text' size='8' value='${materialAttribute}' />
										</td>
										<td>
											<input name='assistantAttribute'
												id='assistantAttribute${status.index}' type='text' size='8'
												value='${assistantAttribute}' />
										</td>
										<td>
											<input type='hidden' id='measureUnitId${status.index}' value='${measureUnitId}'/>
											<input name='measureUnitName'
												id='measureUnitName${status.index}'
												value='${measureUnitName}'
												ondblclick='openWinMeasureUnit(${status.index},750,700,0)'
												onpropertychange='getCostInfo(${status.index})'
												type='text' size='8' />
										</td>
										<td>
											<input name='basicMeasureUnitName'
												id='basicMeasureUnitName${status.index}' readonly='true'
												value='${basicMeasureUnitName}' type='text' size='7' />
										</td>
										<td>
											<input name='basicCost' id='basicCost${status.index}'
												readonly='true' type='text' size='7' value='${basicCost}' />
										</td>
										<td>
											<input name='cost' id='cost${status.index}' type='text' 
												onchange='getBasicCostInfo(${status.index})'
												size='7' value='${cost}' />
										</td>
										<td>
											<input name='lossPercent' id='lossPercent${status.index}'
												type='text' size='8' value='${lossPercent}' />
										</td>
										<td>
											<input name='usedState' id='usedState${status.index}'
												readonly='true' type='text' size='8' value='${usedState}' />
										</td>
										<td>
											<input type='hidden' id='storageId${status.index}'
												value='${storageId}' />
											<input name='storageName' id='storageName${status.index}'
												value='${storageName}'
												ondblclick='openWinStorage(${status.index},750,700,0)'
												type='text' size='7' />
										</td>
									</tr>
								</s:iterator>
							</s:if>
						</tbody>
					</table>
				</div>
				<div align="center" style="margin-top: -2px; margin-bottom: 10px;">
					<input type="button" value="保存" onClick="editBomBill()"
						onFocus="this.blur()" onmouseover="this.className='btnover'"
						onmouseout="this.className='btnout'" class="btnsize" />
					&nbsp;&nbsp;			
					<input type="button" value="返回" onClick="history.go(-1)"
						onFocus="this.blur()" onmouseover="this.className='btnover'"
						onmouseout="this.className='btnout'" class="btnsize" />
					&nbsp;&nbsp;
				</div>
			</div>
		</s:form>
	</body>
</html>